package ev.utility;
import ev.agent.Substation;
import ev.traffic.LineDecision;
import swarm.Selector;
import swarm.Globals;
import swarm.collections.List;
import swarm.collections.ListImpl;
import swarm.collections.ListIndex;
import swarm.simtools.QSortImpl;
public class SwarmUtils{
	public static QSortImpl Qsort;
	public static Selector getSelector(String name,String method){
		Selector sel;
		try{
			sel = new Selector(Class.forName(name),method,false);
		}catch(Exception e){
			e.printStackTrace();
			System.exit(1);
			return null;
		}
		return sel;
	}
	public static Selector getSelector(Object obj,String method){
		Selector sel;
		try{
			sel = new Selector(obj.getClass(),method,false);
		}catch(Exception e){
			e.printStackTrace();
			System.exit(1);
			return null;
		}
		return sel;
	}
	public static List copyList(List list){
		ListIndex li = list.listBegin(Globals.env.globalZone);
		List resultList = new ListImpl(Globals.env.globalZone);
		while(li.next()!=null){
			Substation sub = (Substation)li.get();
			resultList.addLast(sub);
			return resultList;
		}
		li.drop();
		return null;
	}
	public static void sortSubList(int startPoint,int comp,List aList){
		LineDecision.sort(startPoint);
		Qsort = new QSortImpl(Globals.env.globalZone);
		ListIndex li = aList.listBegin(Globals.env.globalZone);
		while(li.next() != null){
				Substation sub = (Substation)li.get();
				sub.setComp(comp);
		}
		Selector sel = getSelector("ev.agent.Substation","compareTo");
		Qsort.sortObjectsIn$using(aList,sel);
		Qsort.drop();
	}
}
